#!/usr/bin/env python
# -*- coding: utf-8 -*-

import csv
import sqlite3
import time

import sys
import os
import math
import pickle

   

def create_db():

    conn = sqlite3.connect("basededados.db")

    c = conn.cursor()
    c.execute('''drop table if exists docentes''')
    c.execute('''create table if not exists docentes (id integer, 
                  Nome text, Ultimo_Grau text, Curso text, Categoria text, Regime_De_Tempo text,
                  Ano_Lectivo text, Tipo_De_Estabelecimento text, Nome_Do_Estabelecimento)''')
    conn.commit()
##    spamReader = csv.reader(open('reb0.csv', 'rb'), delimiter=',')

    for count in range(0,2):

        spamReader = csv.reader(open('reb' + str(count) + '.csv', 'rb'), delimiter=',')
        
        count += 1

        spamReader.next()
        
        for row in spamReader:

            c.execute('''insert into docentes values ("{0}","{1}","{2}","{3}","{4}","{5}","{6}","{7}", "{8}") '''.format(row[0].replace('"','_'),
                                        row[1].replace('"','_'), row[2].replace('"','_'), row[3].replace('"','_'), row[4].replace('"','_'),
                                        row[5].replace('"','_'), row[6].replace('"','_'), row[7].replace('"','_'), row[8].replace('"','_')))
            conn.commit()
            pass
        pass


    conn.close()

    
    print "Base de dados criada"
    
    pass


